﻿using System.Drawing;
using System.Windows.Forms;

/// <summary>
/// 移动窗体类
/// </summary>
public class WinDrog
{

    //拖动label1事件
    private Point _mouseDownPosition;
    private Point Location;
    /// <summary>
    /// 设置背景为透明色
    /// </summary>
    /// <param name="BackgroundImage">图片</param>
    /// <param name="color">变为透明的颜色</param>
    public void SetBakcTransparent(Image BackgroundImage, Color color)
    {
        Bitmap bmp = (Bitmap)BackgroundImage;
        bmp.MakeTransparent(color);
        //TransparencyKey = BackColor;
    }

    /// <summary>
    /// 鼠标左键点击
    /// </summary>
    /// <param name="e"></param>
    public void MouseDownEvent(MouseEventArgs e)
    {
        _mouseDownPosition = e.Location;
    }

    /// <summary>
    /// 鼠标移动
    /// </summary>
    /// <param name="e"></param>
    public void MouseMoveEvent(MouseEventArgs e)
    {
        if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
        {
            int offsetx = e.X - _mouseDownPosition.X;
            int offsety = e.Y - _mouseDownPosition.Y;
            Location = new Point(Location.X + offsetx, Location.Y + offsety);
        }
    }
}
